package com.molichuxing.services.utils;

import com.molichuxing.framework.dto.TabDto;
import com.molichuxing.services.contants.OrderStatusConst;
import com.molichuxing.services.property.OrderExclusivelStatusEnum;
import com.molichuxing.services.property.OrderSubscribeStatusEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TabUtil {

	public static List<TabDto> subscribeTransform(List<OrderSubscribeStatusEnum> statusEnumList,
			List<TabDto> tabDtoList) {
		List<TabDto> result = new ArrayList<>();
		Integer total = 0;
		for (OrderSubscribeStatusEnum orderSubscribeStatusEnum : statusEnumList) {
			TabDto tabDto = new TabDto(orderSubscribeStatusEnum.getName(), orderSubscribeStatusEnum.getValue(), 0);
			for (TabDto tmpTab : tabDtoList) {
				if (tmpTab.getType() == orderSubscribeStatusEnum.getValue()) {
					total += tmpTab.getCount();
					tabDto.setCount(tmpTab.getCount());
				}
			}
			result.add(tabDto);
		}
		result.add(0, new TabDto("全部", null, total));

		return result;
	}

	public static List<TabDto> subscribeCreditTransform(List<OrderSubscribeStatusEnum> statusEnumList,
			List<TabDto> tabDtoList) {
		List<TabDto> result = Arrays.asList(
				new TabDto(OrderSubscribeStatusEnum.TRADE_UNAUDIT.getName(),
						OrderSubscribeStatusEnum.TRADE_UNAUDIT.getValue(), 0),
				new TabDto(OrderSubscribeStatusEnum.TRADE_PASS.getName(),
						OrderSubscribeStatusEnum.TRADE_PASS.getValue(), 0),
				new TabDto(OrderSubscribeStatusEnum.TRADE_REJECTED.getName(),
						OrderSubscribeStatusEnum.TRADE_REJECTED.getValue(), 0));

		for (TabDto tmpTab : tabDtoList) {
			OrderSubscribeStatusEnum statusEnum = OrderSubscribeStatusEnum.getEnum(tmpTab.getType());
			if (OrderSubscribeStatusEnum.TRADE_UNAUDIT.equals(statusEnum)) {
				// 待审核
				TabDto tabDto = result.get(0);
				tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
			} else if (OrderStatusConst.CREDIT_PASS_SUBSCRIBE_STATUS.contains(statusEnum)) {
				// 审核通过
				TabDto tabDto = result.get(1);
				tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
			} else if (OrderStatusConst.CREDIT_REJECT_SUBSCRIBE_STATUS.contains(statusEnum)) {
				// 审核驳回
				TabDto tabDto = result.get(2);
				tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
			}
		}

		return result;
	}

	public static List<TabDto> exclusivelTransform(List<OrderExclusivelStatusEnum> statusEnumList,
			List<TabDto> tabDtoList) {
		List<TabDto> result = new ArrayList<>();
		Integer total = 0;
		for (OrderExclusivelStatusEnum OrderExclusivelStatusEnum : statusEnumList) {
			TabDto tabDto = new TabDto(OrderExclusivelStatusEnum.getName(), OrderExclusivelStatusEnum.getValue(), 0);
			for (TabDto tmpTab : tabDtoList) {
				if (tmpTab.getType() == OrderExclusivelStatusEnum.getValue()) {
					total += tmpTab.getCount();
					tabDto.setCount(tmpTab.getCount());
				}
			}
			result.add(tabDto);
		}
		result.add(0, new TabDto("全部", null, total));

		return result;
	}

	public static List<TabDto> exclusivelCreditTransform(List<OrderExclusivelStatusEnum> statusEnumList,
			List<TabDto> tabDtoList) {
		List<TabDto> result = Arrays.asList(
				new TabDto(OrderExclusivelStatusEnum.TRADE_UNAUDIT.getName(),
						OrderExclusivelStatusEnum.TRADE_UNAUDIT.getValue(), 0),
				new TabDto(OrderExclusivelStatusEnum.TRADE_PASS.getName(),
						OrderExclusivelStatusEnum.TRADE_PASS.getValue(), 0),
				new TabDto(OrderExclusivelStatusEnum.TRADE_REJECTED.getName(),
						OrderExclusivelStatusEnum.TRADE_REJECTED.getValue(), 0));

        for (TabDto tmpTab : tabDtoList) {
            OrderExclusivelStatusEnum statusEnum = OrderExclusivelStatusEnum.getEnum(tmpTab.getType());
            if (OrderExclusivelStatusEnum.TRADE_UNAUDIT.equals(statusEnum)
                    || OrderExclusivelStatusEnum.TRADE_CREDIT_UNAUDIT.equals(statusEnum)) {
                // 待审核
                TabDto tabDto = result.get(0);
                tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
            } else if (OrderStatusConst.CREDIT_PASS_EXCLUSIVEL_STATUS.contains(statusEnum)) {
                // 审核通过
                TabDto tabDto = result.get(1);
                tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
            } else if (OrderStatusConst.CREDIT_REJECT_EXCLUSIVEL_STATUS.contains(statusEnum)) {
                // 审核驳回
                TabDto tabDto = result.get(2);
                tabDto.setCount(tabDto.getCount() + tmpTab.getCount());
            }
        }

		return result;
	}
}
